package com.xiangfei.weixin.utils;

import com.thoughtworks.xstream.XStream;
import com.xiangfei.weixin.bean.MessageText;

import java.util.Date;

public class TextMessageUtil implements BaseMessageUtil<MessageText>{

    /**
     * 将发送消息封装成对应的xml格式
     * @param message
     * @return
     */
    public  String messageToxml(MessageText message){
        XStream xStream = new XStream();
        xStream.alias("xml", message.getClass());
        return xStream.toXML(message);
    }

    public String initMessage(String FromUserName, String ToUserName){

        MessageText text = new MessageText();
        text.setToUserName(FromUserName);
        text.setFromUserName(ToUserName);
        text.setContent("欢迎关注!");
        text.setCreateTime(new Date().getTime());
        text.setMsgType("text");
        return messageToxml(text);
    }

    public String initMessage(String FromUserName, String ToUserName, String Content){
        MessageText text = new MessageText();
        text.setToUserName(FromUserName);
        text.setFromUserName(ToUserName);
        text.setContent("您输入的内容是："+Content);
        text.setCreateTime(new Date().getTime());
        text.setMsgType("text");
        return messageToxml(text);
    }
}
